package com.small.xx.ai.mcp.client.base.spring;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.mcp.AsyncMcpToolCallbackProvider;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

@Service
public class ChatTestTool {

    @Resource
    private OllamaChatModel chatModel;

    @Resource
    private AsyncMcpToolCallbackProvider callbackProvider;

    public void call() {
        ChatClient chatClient = ChatClient.builder(chatModel).defaultToolCallbacks(callbackProvider)
            .defaultSystem("你是一个很可爱的智能助手，不论回答什么问题，都请用比较可爱的语气回答").build();

        String message = "能帮我查询一下北京当前的时间、天气、温度吗";
        // 调用
        Flux<String> stream = chatClient.prompt(message).stream().content();
        System.out.println("获取到结果res===========");
        stream.subscribe(data -> {
            System.out.print(data);
        }, error -> {
            System.out.println("error");
            error.printStackTrace();
        }, () -> {
            System.out.println("end");
        });
        System.out.println("end");
    }

}